﻿@model RequestParcel
@{
    var modelParcel = Model;
    var service = new KPIS.GERP.WEB.GIMS.RequestParcelService.RequestParcelServiceClient();

    int intProjId = Convert.ToInt32(modelParcel.ProjectId);
    string strProjectName = (modelParcel.Project != null ? modelParcel.Project.Name : "ไม่ระบุโครงการ");

    int intWhId = Convert.ToInt32(modelParcel.WarehousePermit.WhId);
    string strWhName = modelParcel.WarehousePermit.Warehouse.Name;

    int intReqBy = Convert.ToInt32(modelParcel.RequestBy);
    string strFullName = service.GetNameRequestBy(intReqBy).ToString();

    ViewBag.JobsiteName = modelParcel.JobSite.Name;
    ViewBag.JobsiteId = modelParcel.JobSiteId;

    ViewBag.CreatedWhen = modelParcel.CreatedWhen.HasValue ? modelParcel.CreatedWhen.Value.ToLongDateString() : "";
    ViewBag.RequestName = modelParcel.RequestName;
    ViewBag.Remarks = modelParcel.Remarks;
    ViewBag.Project = strProjectName;
    ViewBag.Warehouse = strWhName;
    ViewBag.WantedDate = Convert.ToDateTime(modelParcel.WantedDate).ToLongDateString();
    ViewBag.RequestBy = strFullName;

    ViewBag.ProjectId = modelParcel.ProjectId;

    ViewBag.RecordStatus = modelParcel.RecordStatus == "U"?"W":modelParcel.RecordStatus;
    string result = service.GetStatusName(ViewBag.RecordStatus).ToString();
    ViewBag.StatusName = result;
}

<br />
<div class="span11">
    <div class="span5">
        <b>วันที่ทำรายการ : </b>@ViewBag.CreatedWhen
    </div>
</div>

<div class="span11">
    <div class="span5">
        <b>เรื่อง : @ViewBag.RequestName</b>
    </div>
    <div class="span6">
        <b>เหตุผลการขอเบิก : </b>@ViewBag.Remarks
    </div>
</div>

<div class="span11">
    <div class="span5">
        <b>หน่วยงาน : </b>@ViewBag.JobsiteName
    </div>
    <div class="span6">
        <b>โครงการ : </b>@ViewBag.Project
    </div>
</div>

<div class="span11">
    <div class="span5">
        <b>เบิกพัสดุจากคลัง : </b>@ViewBag.Warehouse
    </div>
    <div class="span6">
        <b>วันที่ต้องการพัสดุ : </b>@ViewBag.WantedDate
    </div>
</div>

<div class="span11">
    <div class="span5">
        <b>ผู้ขอ : </b>    @ViewBag.RequestBy
    </div>
    <div class="span6">
        <b>รหัสขอเบิก :     @Model.IcmReqCode</b>
    </div>
</div>

@{
    string cssClass = "";
    switch (Model.RecordStatus)
    {
        case "U":cssClass = "text-info";break; 
        case "A": cssClass = "text-success";break; 
        case "W": cssClass = "text-warning";break; 
        case "P": cssClass = "muted";break; 
        case "J": cssClass = "red";break; 
        default: break; }
}

<div class="span11">
     
        @{
            var db = new GERPContext(true);
            var task2 = db.Tasks
                .Include(o => o.CurrentTaskHistory)
                .FirstOrDefault(o => o.RefId == modelParcel.ReqParcelId &&
                                     o.ApproveProcess.AppPrcGrpId == 7
                                     && o.RecordStatus != RecordStatus.DeletedStatus);
        }
        <b>สถานะ : </b><u class="@cssClass" title="@Model.RecordStatus">@ViewBag.StatusName</u>
        @if (task2 != null && modelParcel.RecordStatus != RecordStatus.ReturnedStatus)
        {
            var x = "";
            @:&nbsp;&nbsp;&nbsp;&nbsp;
    <a href="@Url.Action("Details", "Task", new {id=task2.TaskId})" target="_blank" title="ไปที่หน้าคำขอ" >
        <i class="icon-external-link"></i>
    </a>
        }
        else if (modelParcel.RecordStatus == RecordStatus.ReturnedStatus)
        {
            @:&nbsp;&nbsp;&nbsp;&nbsp;
    <a href="@Url.Action("Details", "Task", new {id=task2.TaskId})" target="_blank" style="background-color: rgb(255, 255, 180);
                                                                                                                                                                                                                                  font-size:14px;
                                                                                                                                                                                                                                  font-weight: bold;                                                                                                                                  ">
        ส่งกลับไปขออนุมัติต่อ (ต้องเป็นผู้สร้างคำขอ)<i class="icon-external-link"></i>
    </a>
        } 
</div>

<br />